package com.wandian.data
{
	
	import com.wandian.core.LoaderManager;
	import com.wandian.data.LevelVO;
	import com.wandian.util.VOUtil;
	
	import flash.utils.Dictionary;

	/**
	 * 数据管理 
	 * @author long
	 * 
	 */	
	public class DataManager
	{
		private static var _I :DataManager = null;
		/**
		 * 等级数据 
		 */		
		public var levelList :Array;
		public function DataManager(prv :PrivateClass)
		{
		}
		

		public static function get I():DataManager
		{
			if(_I == null)
			{
				_I = new DataManager(new PrivateClass());
			}
			return _I;
		}
		
		/**
		 * 初始化等级数据 
		 * 
		 */		
		public function initLevelList():void
		{
			var dict :Dictionary = LoaderManager.instance.txtDict;
			var str :String = dict["level"];
			
			if(str)
			{
				this.levelList = VOUtil.I.createList(str,LevelVO);
			}
			
		}
		
		public function  curLevel(exp :int):int
		{
			
			if(!this.levelList || this.levelList.length == 0)
			{
				return 0;
			}
			var levelVO :LevelVO;
			for (var i :int = 0 ; i < this.levelList.length; i++)
			{
				levelVO = this.levelList[i] as LevelVO;
				
				if(levelVO.exp > exp)
				{
					return (this.levelList[i - 1] as LevelVO).level;
				}
			}
			
			return ((this.levelList[levelList.length - 1]) as LevelVO).level;
		}

	}
}

class PrivateClass{}